/*
This file is a part of MonaSolutions Copyright 2017
mathieu.poux[a]gmail.com
jammetthomas[a]gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License received along this program for more
details (or else see http://www.gnu.org/licenses/).

*/

#pragma once

#include "Mona/Mona.h"
#include "Mona/DataReader.h"

namespace Mona {

struct SplitReader : DataReader, virtual Object {
	template <class ...Args>
	SplitReader(DataReader& reader,Args&&... args) { addReader(reader,args ...); }

	template <class ...Args>
	void addReader(DataReader& reader,Args&&... args) {
		_readers.emplace_back(&reader);
		addReader(args ...);
	}

	void reset() {
		for (DataReader* pReader : _readers)
			pReader->reset();
	}

private:
	UInt8	followingType() {
		for (DataReader* pReader : _readers) {
			if (pReader->nextType() != END) {
				_pReader = pReader;
				return pReader->nextType();
			}
		}
		return END;
	}
	bool	readOne(UInt8 type, DataWriter& writer) { return _pReader->read(type, writer); }
	
	void addReader() {}

	std::vector<DataReader*> _readers;
	DataReader*				 _pReader;
};



} // namespace Mona
